﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer
{
    public partial class Request
    {
        public static Request FindByRequestID_IncludeDeleted(linqDatabaseDataContext db, int RequestID)
        {
            var subquery = (from u in db.Requests where u.ID == (from v in db.Requests where v.RequestID == u.RequestID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where u.RequestID == RequestID select u).SingleOrDefault());
        }

        public static Request FindByRequestID(linqDatabaseDataContext db, int RequestID)
        {
            var subquery = (from u in db.Requests where u.ID == (from v in db.Requests where v.RequestID == u.RequestID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where !u.IsDeleted && u.RequestID == RequestID select u).SingleOrDefault());
        }

        public static List<Request> ToList_IncludeDeleted(linqDatabaseDataContext db)
        {
            var subquery = (from u in db.Requests where u.ID == (from v in db.Requests where v.RequestID == u.RequestID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery select u).ToList());
        }

        public static List<Request> ToList(linqDatabaseDataContext db)
        {
            var subquery = (from u in db.Requests where u.ID == (from v in db.Requests where v.RequestID == u.RequestID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where !u.IsDeleted select u).ToList());
        }

        public static List<Request> HistoryToListByRequestID(linqDatabaseDataContext db, int RequestID)
        {
            return (from u in db.Requests where u.RequestID == RequestID orderby u.Timestamp ascending select u).ToList();
        }
    }
}
